/**
*      author: Y_Yao
*      created: 2024-12-20 22:36:12
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 1e18;
const int INF = 0x3f3f3f3f;
const int N = 50 + 7;
int n;
int  a[N];

void solve()
{
    cin >> n;
    int cnt = 0;
    for(int i = 1;i <= n;i++)
    {
        cin >> a[i];
        if(a[i] == 0) cnt++;
    }
    if(cnt == n)
    {
        cout << 0 << endl;
        return;
    }

    int l = 1,r = n;
    while(a[l] == 0)
    {
        l++;
        cnt--;
    }
    while(a[r] == 0)
    {
        r--;
        cnt--;
    }

    if(cnt == 0 || l == r)
    {
        cout << 1 << endl;
        return;
    }
    cout << 2 << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}